****TABLE 10****

cd "$main_dir/output/tables/main"

global basic 	sex marital religion edu

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/harmonized_dataset.dta"

merge m:1 ccode survey_year yob using "$data_dir/raw/lifeexp_variables_data/growth_rate_mpd_var_exp.dta", nogen keepusing(total_growth_rate_obs wgrowth_rate_1 yob_ln_gdppc)
merge m:1 ccode survey_year yob using "$data_dir/raw/lifeexp_variables_data/democracy_var_exp.dta", nogen keepusing(wdemocracy_1)

merge m:1 ccode using "$data_dir/raw/democ_autoc_switch_media.dta"
drop if _merge==2
drop _merge

fegen subregion_yob = group(subregion yob) if yob!=-99
fegen svy_survey_year = group(survey_year survey)

cap drop sample
gen sample = 1 if born_country!=0 & total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=.

//--------------------------------------------------------
//Create table
//--------------------------------------------------------

//Column 1													   
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1 & democracy==1, absorb(ccode svy_survey_year subregion_yob age $basic) cluster(ccode)
cap drop z*										   
local varlist trust_govt wgrowth_rate_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if e(sample)==1, absorb(ccode svy_survey_year subregion_yob age $basic) cluster(ccode)
outreg2 using table_10.doc, replace dec(3) nocons addtext(Country FE, Yes, ///
													      Survey Year FE x Survey FE, Yes, ///
													      Subcontinent FE x Cohort FE, Yes, ///
													      Sample, Democracies) keep(zwgrowth_rate_1) 

//results interpretation
qui summ trust_govt if e(sample)==1 & ccode=="GRC"
qui scalar beta_grc = _b[zwgrowth_rate_1]*r(sd)
qui summ trust_govt if e(sample)==1 & ccode=="GRC" & cohort=="1950s"
qui scalar trust_grc_50s = r(mean)
qui summ trust_govt if e(sample)==1 & ccode=="GRC" & cohort=="1990s"
qui scalar trust_grc_90s = r(mean)
di abs(beta_grc)/(abs(trust_grc_50s-trust_grc_90s))
summ wgrowth_rate_1 if e(sample)==1 & ccode=="GRC"

qui summ trust_govt if e(sample)==1 & ccode=="ESP"
qui scalar beta_esp = _b[zwgrowth_rate_1]*r(sd)
qui summ trust_govt if e(sample)==1 & ccode=="ESP" & cohort=="1950s"
qui scalar trust_esp_50s = r(mean)
qui summ trust_govt if e(sample)==1 & ccode=="ESP" & cohort=="1990s"
qui scalar trust_esp_90s = r(mean)
di abs(beta_esp)/(abs(trust_esp_50s-trust_esp_90s))
summ wgrowth_rate_1 if e(sample)==1 & ccode=="ESP"														  

//Column 2													   
qui reghdfe trust_govt wgrowth_rate_1 wdemocracy_1 yob_ln_gdppc if sample==1 & democracy==1, absorb(ccode svy_survey_year subregion_yob age $basic) cluster(ccode)
cap drop z*										   
local varlist trust_govt wgrowth_rate_1 wdemocracy_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}
reghdfe ztrust_govt zwgrowth_rate_1 zwdemocracy_1 zyob_ln_gdppc if e(sample)==1, absorb(ccode svy_survey_year subregion_yob age $basic) cluster(ccode)
outreg2 using table_10.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													      Survey Year FE x Survey FE, Yes, ///
													      Subcontinent FE x Cohort FE, Yes, ///
													      Sample, Democracies) keep(zwgrowth_rate_1 zwdemocracy_1) 

//Column 3
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1 & switcher==1, absorb(ccode svy_survey_year subregion_yob age $basic) cluster(ccode)
cap drop z*										   
local varlist trust_govt wgrowth_rate_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if e(sample)==1, absorb(ccode svy_survey_year subregion_yob age $basic) cluster(ccode)
outreg2 using table_10.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													      Survey Year FE x Survey FE, Yes, ///
													      Subcontinent FE x Cohort FE, Yes, ///
													      Sample, Switchers) keep(zwgrowth_rate_1) 

//Column 4
qui reghdfe trust_govt wgrowth_rate_1 wdemocracy_1 yob_ln_gdppc if sample==1 & switcher==1, absorb(ccode svy_survey_year subregion_yob age $basic) cluster(ccode)
cap drop z*										   
local varlist trust_govt wgrowth_rate_1 wdemocracy_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}
reghdfe ztrust_govt zwgrowth_rate_1 zwdemocracy_1 zyob_ln_gdppc if e(sample)==1, absorb(ccode svy_survey_year subregion_yob age $basic) cluster(ccode)
outreg2 using table_10.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													      Survey Year FE x Survey FE, Yes, ///
													      Subcontinent FE x Cohort FE, Yes, ///
													      Sample, Switchers) keep(zwgrowth_rate_1 zwdemocracy_1) 	


//Column 5											  
qui reghdfe trust_govt wgrowth_rate_1 yob_ln_gdppc if sample==1 & autocracy==1, absorb(ccode svy_survey_year subregion_yob age $basic) cluster(ccode)
cap drop z*										   
local varlist trust_govt wgrowth_rate_1 yob_ln_gdppc
foreach var of local varlist {
	egen z`var' = std(`var') if e(sample)==1
}														  
reghdfe ztrust_govt zwgrowth_rate_1 zyob_ln_gdppc if e(sample)==1, absorb(ccode svy_survey_year subregion_yob age $basic) cluster(ccode)
outreg2 using table_10.doc, append dec(3) nocons addtext(Country FE, Yes, ///
													      Survey Year FE x Survey FE, Yes, ///
													      Subcontinent FE x Cohort FE, Yes, ///
													      Sample, Autocracies) keep(zwgrowth_rate_1) 
														  
